package doudou.pojo;

import doudou.Interface.NetService;

import java.io.Serializable;

//流量套餐
public class NetPackage extends ServicePackage implements NetService, Serializable {
    public NetPackage() {
        super("网虫套餐", 68, 0, 3036, 0);
    }

    public void showInfo() {
        super.showInfo();
    }

    public int netPlay(int minCount, MobileCard card) {
        int net = card.getRealFlow();
        int useNet;
        double restMoney;
        if (net >= minCount) {
            useNet = minCount;
            card.setRealFlow(net - minCount);
        } else {
            int overFlow = minCount - net;
            double cost = overFlow * 0.1;
            restMoney = card.getMoney() - cost;
            if (restMoney > 0) {
                useNet = minCount;
                card.setRealFlow(0);
                card.setMoney(restMoney);
                card.setConsumAmount(card.getConsumAmount() + cost);
            } else {
                int extraFlow = (int) (card.getMoney() / 0.1);
                useNet = net + extraFlow;
                card.setRealFlow(0);
                card.setMoney(0);
                card.setConsumAmount(card.getConsumAmount() + (extraFlow*0.1));
                try {
                    throw new Exception("您已使用" + useNet + "MB流量，您的余额不足，请充值后使用");
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }
        return useNet;
    }
}